package tests;

import java.io.File;
import java.io.IOException;
/**
 * 
 * @author 浮生若梦
 * @Title 创建文件
 * @param
 */
public class CreateFile {
	public static void main(String[] args) {
		File directory = new File("");// 设定为当前文件夹
		// System.out.println(directory.getCanonicalPath());
		System.out.println(directory.getAbsolutePath());// 获取绝对路径
		traverseFolder2(directory.getAbsolutePath());
	}

	public static void traverseFolder2(String path) {
		File file = new File(path);
		if (file.exists()) {
			File[] files = file.listFiles();
			if (files.length == 0) {
				System.out.println("文件夹是空的!");// 如果是空文件夹就创建llad.java文件
				String fileName = "llad.java";
				File file3 = new File(file, fileName);
				if (!file3.exists()) {
					try {
						file3.createNewFile();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
				return;
			} else {
				for (File file2 : files) {
					if (file2.isDirectory()) {
						// 是目录,递归
						System.out.println("文件夹:" + file2.getAbsolutePath());
						traverseFolder2(file2.getAbsolutePath());
					} else {
						System.out.println("文件:" + file2.getAbsolutePath());
					}
				}
			}
		} else {
			System.out.println("文件不存在!");
		}
	}

}
